// 题意：给n个区间以及对应的ci，求最小的整数集Z使得在每个区间上至少有ci个，
//       区间范围是[0, 50000]。
//
// 题解：可以用差分约束做。设sum[i]表示从0加到i的位置有几个整数
//       （为了方便可以把区间都加1从1开始），然后满足一些约束方程。
//       最后求的从0到50001（或到者最右的端点）的最短路就是最小的Z。
//
// run: time $exec < input
#include <cstdio>
#include <algorithm>
#include <vector>

template <class T>
struct shortest_path_faster_algorithm
{
	typedef T value_type;
	typedef int size_type;

	struct edge {
		edge(size_type from, size_type to, value_type cost) : from(from), to(to), cost(cost) {}
		int from, to, cost;
	};

	typedef std::vector<edge> adj_edge;
	typedef typename adj_edge::iterator edge_iter;
	typedef std::vector<adj_edge> graph_type;
//	enum { inf = 1 << 28 };
	int static const inf = 1 << 28;

	shortest_path_faster_algorithm(size_type n) : n(n)
	{
		graph.resize(n);
		dist.resize(n);
		in_queue.resize(n);
		count_into_que.resize(n);
		dq_size = 2 * n;
		dq.resize(dq_size);
	}

	void add_edge(size_type from, size_type to, value_type cost)
	{
		graph[from].push_back(edge(from, to, cost));
	}

	value_type spfa(size_type source, size_type target)
	{
		std::fill(dist.begin(), dist.end(), +inf);
		std::fill(in_queue.begin(), in_queue.end(), false);
		clear();
		push_back(source);
		dist[source] = 0;
		in_queue[source] = true;
		count_into_que[source]++;
		while (!empty()) {
			size_type now = front();
			in_queue[now] = false;
			pop_front();

			for (edge_iter it = graph[now].begin(); it != graph[now].end(); ++it) {
				size_type v = it->to;
				value_type c = it->cost;
				if (dist[v] > dist[now] + c) {
					dist[v] = dist[now] + c;
					if (!in_queue[v]) {
						if (count_into_que[v] >= n) return -inf;
						if (!empty() && dist[v] < dist[front()])
							push_front(v);
						else
							push_back(v);
						in_queue[v] = true;
						count_into_que[v]++;
					}
				}
			}
		}
		return dist[target];
	}

private:
	size_type next(int x) { return (x + 1) % dq_size; }
	size_type prev(int x) { return (x + dq_size - 1) % dq_size; }
	void clear() { head = tail = 0; }
	bool empty() { return head == tail; }
	size_type front() { return dq[head]; }
	void push_back(size_type x) { dq[tail] = x; tail = next(tail); }
	void push_front(size_type x) { dq[head = prev(head)] = x; }
	void pop_front() { head = next(head); }

	graph_type graph;
	size_type n;
	size_type dq_size;
	size_type head, tail;
	std::vector<size_type> dq;
	std::vector<size_type> count_into_que;
	std::vector<value_type> dist;
	std::vector<char> in_queue; // FIXME std::vector<bool>;
};

struct data
{
	int l, r, c;
};

int const maxn = 50004;
data da[maxn];
int n, max_r;

int main()
{
	std::scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		std::scanf("%d%d%d", &da[i].l, &da[i].r, &da[i].c);
		da[i].l++; da[i].r++;
		max_r = std::max(max_r, da[i].r);
	}

	shortest_path_faster_algorithm<int> sp(max_r + 1);
	for (int i = 1; i <= max_r; i++) {
		sp.add_edge(i, i - 1, 1);
		sp.add_edge(i - 1, i, 0);
	}
	for (int i = 0; i < n; i++)
		sp.add_edge(da[i].l - 1, da[i].r, -da[i].c);
	std::printf("%d\n", -sp.spfa(0, max_r));
}

